import random

def weighted_choice(*args, **kwargs):
    if kwargs:
        items = kwargs.items()
    elif type(args[0]) is dict:
        items = args[0].items()
    else:
        items = list(args[0])
    r = random.random() * sum(weight for key, weight in items)
    for key, weight in items:
        if r < weight:
            return key
        r -= weight
    key, weight = random.choice(items)
    return key

def chance(fraction):
    return random.random() < fraction

def percent_chance(percent):
    return random.randrange(100) < percent
